package com.test.http;

import java.net.URLEncoder;

import com.test.config.HttpDefine;

public class HttpMethod {
	//HTTP请求地址
	static public String HTTP_URL_ROOT = HttpDefine.URL;
	//HTTP请求SessionID
	static public String SESSION_ID = HttpDefine.SESSION_ID;
	
	//编码
	static public String encode(String str){
		str = URLEncoder.encode(str);
		return str;
	}
	
	//添加SessionID
	static public String addSessionID(String param){		
		if(param.equals("")){
			param = "sessionId=" + URLEncoder.encode(SESSION_ID);
		}else{
			param = param + "&sessionId=" + URLEncoder.encode(SESSION_ID);
		}
		
		return param;
	}
	
	//添加参数
	static public String addParam(String param,String Key,String Value){		
		if(param.equals("")){
			param = Key + "=" + URLEncoder.encode(Value);
		}else{
			param = param + "&" + Key + "=" + URLEncoder.encode(Value);
		}
		
		return param;
	}
	
	/**
	 * 用户登录
	 * @param recevier ：返回消息接受者
	 * @param name ：用户名
	 * @param password ： 密码
	 */
	static public void login(HttpClientReceiver recevier,
			String name,
			String password){
		String url = "";
		String param = "";
		
		url = HTTP_URL_ROOT + "/front/login_check.action";
		param = addParam(param,"username",name);
		param = addParam(param,"password",password);
		
		HttpClientSender sender = new HttpClientSender();
		sender.httpRequestThread(recevier,
				url,
				param,
				HttpMethodTag.LOGIN);
	}
	
	
	/**
	 * 退出登录
	 * @param recevier ：返回消息接受者
	 */
	static public void logout(HttpClientReceiver recevier){
		String url = "";
		String param = "";
		
		url = HTTP_URL_ROOT + "/front/logout.action";
		param = addSessionID(param);
		
		HttpClientSender sender = new HttpClientSender();
		sender.httpRequestThread(recevier,
				url,
				param,
				HttpMethodTag.LOGOUT);
	}
	
	/**
	 * 注册用户名合法性检查
	 * @param recevier ： 返回消息接受者
	 * @param userID ：用户ID
	 */
	static public void registIDCheck(HttpClientReceiver recevier,
			String userID){
		String url = "";
		String param = "";
		
		url = HTTP_URL_ROOT + "/front/register_check.action";
		param = addParam(param,"loginId",userID);
		
		HttpClientSender sender = new HttpClientSender();
		sender.httpRequestThread(recevier,
				url,
				param,
				HttpMethodTag.REGIST_ID_CHECK);
	}
	
	
	/**
	 * 用户注册
	 * @param recevier ： 返回消息接收者
	 * @param userID ：用户ID
	 * @param password ：登录密码
	 * @param userName ：用户名
	 * @param email ：用户邮箱
	 * @param phone ： 用户电话
	 */
	static public void regist(HttpClientReceiver recevier,
			String userID,
			String password,
			String userName,
			String email,
			String phone){
		String url = "";
		String param = "";
		
		url = HTTP_URL_ROOT + "/front/userAdd.action";
		param = addParam(param,"loginId",userID);
		param = addParam(param,"userName",userName);
		param = addParam(param,"userPass",password);
		param = addParam(param,"email",email);
		param = addParam(param,"phone",phone);
		
		HttpClientSender sender = new HttpClientSender();
		sender.httpRequestThread(recevier,
				url,
				param,
				HttpMethodTag.REGIST);
	}
	
	
	/**
	 * 获取大厅列表
	 * @param recevier ： 返回消息接受者
	 */
	static public void getHallList(HttpClientReceiver recevier){
		String url = "";
		String param = "";
		
		url = HTTP_URL_ROOT + "/front/shareImageList.action";
		param = addSessionID(param);
		
		HttpClientSender sender = new HttpClientSender();
		sender.httpRequestThread(recevier,
				url,
				param,
				HttpMethodTag.HALL_LIST);
	}
	
	
	/**
	 * 获取喜爱列表
	 * @param recevier ： 返回消息接受者
	 */
	static public void getRankList(HttpClientReceiver recevier){
		String url = "";
		String param = "";
		
		url = HTTP_URL_ROOT + "/front/topImageList.action";
		param = addSessionID(param);
		
		HttpClientSender sender = new HttpClientSender();
		sender.httpRequestThread(recevier,
				url,
				param,
				HttpMethodTag.RANK_LIST);
	}
	
	
	/**
	 * 获取喜爱列表
	 * @param recevier ：返回消息接受者
	 */
	static public void getLikeList(HttpClientReceiver recevier){
		String url = "";
		String param = "";
		
		url = HTTP_URL_ROOT + "/front/likeImageList.action";
		param = addSessionID(param);
		
		HttpClientSender sender = new HttpClientSender();
		sender.httpRequestThread(recevier,
				url,
				param,
				HttpMethodTag.LIKE_LIST);
	}
}
